//
//  UIAlertAction+CLUtility.m
//  CLBrowser
//
//  Created by 梁慧聪 on 2017/9/25.
//  Copyright © 2021年 梁慧聪. All rights reserved.
//

#import "UIAlertAction+CLUtility.h"
#import "CLVCMain.h"
#import "UIView+CLUtility.h"
static NSString *const kCancelString = @"取消";

@implementation UIAlertAction (CLUtility)

+ (UIAlertAction *)actionCopyLinkWithURL:(NSURL *)linkURL{
    UIAlertAction *copyAction = [UIAlertAction actionWithTitle:@"拷贝链接" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
        UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
        pasteBoard.URL = linkURL;
        [[CLMainVC navigationController].view showHUDAtBottomWithMessage:@"拷贝成功"];
    }];
    return copyAction;
}

+ (UIAlertAction *)actionOpenNewTabWithCompletion:(void (^)(void))completion{
    UIAlertAction  *openNewTabAction = [UIAlertAction actionWithTitle:@"在新窗口打开" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
        if (completion) {
            completion();
        }
    }];
    return openNewTabAction;
}

+ (UIAlertAction *)actionDismiss{
    UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:kCancelString style:UIAlertActionStyleCancel handler:nil];
    return dismissAction;
}

+ (UIAlertAction *)actionSettings{
    UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:@"打开设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
#pragma clang diagnostic pop
    }];
    return settingsAction;
}

@end
